<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        v-model="form"
        v-bind="bindVal"
        v-on="onEvent"
        :page.sync="page"
        :permission="permissionList"
        :upload-preview="uploadPreview">
        <template slot-scope="scope" slot="menuLeft">
          <el-button type="primary" size="small" @click.stop="handleExport">导 出</el-button>
          <el-button type="primary" size="small" :hidden="true" v-if="false" @click.stop="handlePrint">打 印</el-button>
        </template>
        <template slot-scope="scope" slot="menu">
          <el-button icon="el-icon-view" :type="scope.type" :size="scope.size" @click.stop="showView(scope.row)">预 览</el-button>
          <el-button v-if="scope.row.isReceive!='是'"  :type="scope.type" :size="scope.size" @click.stop="XiaoHui(scope.row)">销毁</el-button>
        </template>
      </avue-crud>
    </basic-container>
    <open-dialog :DialogVisible.sync="viewVisible" title="预 览">
      <avue-form v-model="viewForm" :option="viewOption"></avue-form>
      <div slot="footer" style="width: 100%; text-align: center;">
        <el-button type="primary" @click="viewVisible=false">返 回</el-button>
      </div>
    </open-dialog>
    <open-dialog :DialogVisible.sync="XiaoHuiVisDialog" title="销毁"  width="80%">
      <el-form label-width="60px">
        <avue-form ref="xiaoHuiForm" v-model="form" :option="tableOptionXiaoHui" style="margin-bottom:40px;"></avue-form>
        <div class="bottom-menu">
          <el-button type="primary" @click="edit">确认</el-button>
          <el-button type="primary" @click="XiaoHuiVisDialog=false">取消</el-button>
        </div>
      </el-form>
    </open-dialog>
  </div>
</template>

<script>
import baseCrud from '@/mixins/base-crud'
import {
  addObj,
  delObj,
  fetchList,
  putObj,
  destroyObj,
  exportExcel
} from "@/api/subway/swstticketdestroy";
import {
  tableOption,
  tableOptionXiaoHui,startDate, endDate
} from "@/const/crud/subway/swstticketdestroy";

export default {
  name: "StTicketDestroy",
  mixins: [baseCrud('subway/swstticketdestroy')],
  data() {
    return {
      exportName: '车票销毁.xlsx',
      fileList: [],
      enabledUploadBtn: true,
      uploadBtnIcon: "el-icon-upload2",
      tableOptionXiaoHui: tableOptionXiaoHui,
      XiaoHuiVisDialog: false,
      viewForm: {},
      viewVisible: false,
      searchForm: {
        dates1: [startDate, endDate]
      }
    };
  },
  computed: {
    permissionList() {
      return {
        addBtn: this.vaildData(this.permissions.st_plan_year_add, false)
      }
    },
    viewOption() {
      return Object.assign({}, this.tableOption, {detail: true})
    }
  },
  methods: {
    getList(page) {
      this.tableLoading = true
      return fetchList(Object.assign({
        current: page.currentPage,
        size: page.pageSize
      }, this.params, this.searchForm)).then(response => {
        this.tableData = response.data.data.records
        this.tableData.forEach(row => {
          row.stockArea = Number(row.stockArea)
        })
        this.page.total = response.data.data.total
        this.tableLoading = false
      })
    },
    XiaoHui(row) {
      this.form = row;
      this.XiaoHuiVisDialog = true;
    },
    edit() {
      this.$refs.xiaoHuiForm.validate(valid => {
        if(valid){
          destroyObj(this.form).then(() => {
            this.$message.success("销毁成功");
            this.getList(this.page);
            this.XiaoHuiVisDialog = false;
          });
        }
      })
    },
    handleEdit(row, index) {
      this.$refs.crud.rowEdit(row, index);
    },
    handleDel(row, index) {
      this.$refs.crud.rowDel(row, index);
    },
    handleCancel: function (row, index) {
      row.checkStatus = 0;
      var _this = this;
      this.$confirm("是否确认取消通知该数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return putObj(row);
        })
        .then(() => {
          this.getList(this.page);
          _this.$message({
            showClose: true,
            message: "取消通知成功",
            type: "success",
          });
        })
        .catch(function () {});
    },
    operBtn(row) {
      if (row.isReceive == "否") {
        return false;
      } else {
        return true;
      }
    },
    auditBtn(row) {
      if (row.isReceive == "否") {
        return true;
      } else {
        return false;
      }
    },
    resolveBtn(row) {
      if (row.isReceive == "是") {
        return false;
      } else {
        return true;
      }
    },
    handleAdd: function () {
      this.$refs.crud.rowAdd();
    },
    rowSave: function (row, done) {
      if(row.file.length==0){
        row.file=null
      }
      row.checkStatus = 0;
      addObj(row).then(() => {
        this.$message({
          showClose: true,
          message: "添加成功",
          type: "success",
        });
        done();
        this.getList(this.page);
      });
    },
    handleAudit(row, index) {
      this.form.nowOpenId = row.id;
      this.dialogAuditVisible = true;
    },
    doConfirm() {
      let obj = {};
      obj.id = this.form.nowOpenId;
      obj.checkStatus = "是"; //通过
      destroyObj(obj).then(() => {
        this.$message({
          showClose: true,
          message: "销毁操作成功",
          type: "success",
        });
        this.dialogAuditVisible = false;
        this.getList(this.page);
      });
    },
    uploadPreview(file, column, done) {
      console.log(file, column);
      console.log(file.url);
      var strRegex = "(.jpg|.png|.jpeg)$";
      var re = new RegExp(strRegex);
      if (!re.test(file.url)) {
        window.location.href = file.url;
      } else {
        window.location.href = file.url;
        done();
      }
    },
    showView(row) {
      this.viewForm = row
      this.viewVisible = true
    }
  },
};
</script>

<style lang="scss" scoped>
</style>
